package edu.je.prs.Service;

import com.alibaba.fastjson.JSON;
import com.junqson.je.common.constant.AppConstant;
import com.junqson.je.common.constant.AppRedisKey;
import com.junqson.je.common.model.ApiResult;
import edu.je.prs.Mapper.ResumeInfoMapper;
import edu.je.prs.Model.ResumeInfo;
import edu.je.prs.vo.UserTagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Description:
 * @author: Anhlaidh
 * @date: 2021-04-20 19:42
 */
@Service
public class UserService {
    @Autowired
    ResumeInfoMapper resumeInfoMapper;
    @Autowired
    StringRedisTemplate redisTemplate;
    public ApiResult getUserTags(int id) {
        ResumeInfo resumeInfo = resumeInfoMapper.selectByPrimaryKey(id);
        List<UserTagVo> list = new ArrayList<>();
        list.add(new UserTagVo(resumeInfo.getAttachment()));
        list.add(new UserTagVo(resumeInfo.getGender()));
        list.add(new UserTagVo( resumeInfo.getAddress()));
        list.add(new UserTagVo( resumeInfo.getSchool()));
        list.add(new UserTagVo( resumeInfo.getMajor()));
        String skillstr = resumeInfo.getSkills();
        String[] skills = skillstr.split(",");
        for (int i = 0; i < skills.length; i++) {
            list.add(new UserTagVo(skills[i]));
        }
        for (int i = 0; i < list.size(); i++) {
            float random = (float) (Math.random()/2+0.5);
            list.get(i).setValue(random);
        }
        redisTemplate.opsForValue().set(AppRedisKey.TAGS_HEADER+id, JSON.toJSONString(skills));


        return ApiResult.success(list);
    }

}
